
$(function(){
	click_refresh();
});

function click_refresh(){
	$("#dg3").edatagrid({ url:'./bills.json'});
	$.ajax(frame.fullUrl("/trade/synch/getstatus.json"),{
		mask:true, 
		success:function(data) {
			if(data.positions){
				$("#dg1").datagrid("loadData",data.positions);
				$("#ff1").form("load",data.summary);
			}
		}
	});
	$.ajax(frame.fullUrl("/trade/synch/getexstatus.json"),{
		mask:true, 
		success:function(data) {
			if(data.positions){
				$("#dg2").datagrid("loadData",data.positions);
				$("#ff2").form("load",data.summary);
			}
		}
	});
}

function secNameFormatter(value, row, index) {
	return frame.flex.getName("SMDC_SECURITY_SEL", row.secId);
}

function click_delete(){
	$.messager.confirm('确认','您确认想要删除吗？',
			function(r){    
			    if (r){
			    	delete_selected_data();
			    }
			}
		);
}

function delete_selected_data(){
	var billIds="";
	var selData = $("#dg3").edatagrid("getSelections");
	for(var i=0;i<selData.length;i++){
		billIds += ","+selData[i].billId;
	}
	if(!billIds.length>1){
		return;
	}
	billIds=billIds.substr(1);
	$.post("./delete.json",
			{billIds:billIds},
	 		function(data) {
				if(data.sucesse==true){
					$('#dg3').edatagrid("clearSelections");
					$('#dg3').edatagrid("reload");
				}
			}
	);
}

function click_synchnize(){
	var startDate = $("#startDate").datebox("getValue");
	$.ajax(frame.fullUrl("/trade/synch/synchbill.json"),{
			mask:true,
			data:{startDate:startDate},
			success:function(data) {
				if(data.rows){
					$("#dg3").edatagrid("loadData", data);
				}
			}
		});
}

function profitStyle(value,row,index){
	if (value > 0){
		return 'color:red;';
	} else if (value < 0){
		return 'color:green;';
	}
}